package com.nhjf.service.impl.finetTalk;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.nhjf.dao.finetTalk.FinetTalkDao;
import com.nhjf.dao.teachers.TeachersDao;
import com.nhjf.model.finetTalk.FinetTalk;
import com.nhjf.model.teachers.Teacher;
import com.nhjf.pojo.dto.result.ServiceResultDto;
import com.nhjf.pojo.qo.finetTalk.FinetTalkQo;
import com.nhjf.pojo.qo.teachers.TeachersQo;
import com.nhjf.service.finetTalk.FinetTalkService;
import com.nhjf.service.impl.BaseServiceImpl;

@Transactional
@Service("finetTalkService")
public class FinetTalkServiceImpl extends BaseServiceImpl<FinetTalk,FinetTalkQo,FinetTalkDao>implements FinetTalkService{

	@Autowired
	private FinetTalkDao finetTalkDao;
	@Autowired
	private TeachersDao teacherDao;

	@Override
	protected FinetTalkDao getDao() {
		// TODO Auto-generated method stub
		return finetTalkDao;
	}

	@Override
	public ServiceResultDto findadd(FinetTalkQo finettalk) {
		// TODO Auto-generated method stub
		ServiceResultDto resultDto = new ServiceResultDto();
		FinetTalk Addtofinettalk=new FinetTalk();
		if(finettalk==null){
			resultDto.setSuccess(false);
			resultDto.setResultMessage("非法操作");
			return resultDto;
		}
		//封面
		if(finettalk.getImge()!=null) {
			Addtofinettalk.setImge(finettalk.getImge());
		}else{
			resultDto.setResultMessage("封面为空");
			resultDto.setSuccess(false);
			return resultDto;
		}
		//浏览量
		if(finettalk.getPageviews()!=null) {
			Addtofinettalk.setPageviews(finettalk.getPageviews());
		}
		//标题
		if(finettalk.getTitle()!=null) {
			Addtofinettalk.setTitle(finettalk.getTitle());
		}
		if(finettalk.getNavigation()!=null) {
			Addtofinettalk.setNavigation(finettalk.getNavigation());
		}
		if(finettalk.getTopping()!=null && finettalk.getTopping()==1) {
			Addtofinettalk.setTopping(1);
		}else {
			Addtofinettalk.setTopping(0);
		}
		if(finettalk.getTopping()==1) {
			Addtofinettalk.setSerialNumber(finettalk.getSerialNumber());
		}

		//发布人
		if(finettalk.getPublisher()!=null) {
				Addtofinettalk.setPublisher(finettalk.getPublisher());
			
		}
		//内容
		if(finettalk.getContent()!=null) {
			Addtofinettalk.setContent(finettalk.getContent());
		}
		Addtofinettalk.setReleasetime(new Date());
		finetTalkDao.save(Addtofinettalk);
		resultDto.setSuccess(true);
		return resultDto;
	}

	//精讲修改
	@Override
	public ServiceResultDto findmodify(FinetTalkQo finettalk) {
		// TODO Auto-generated method stub
		ServiceResultDto resultDto = new ServiceResultDto();
		FinetTalkQo qo=new FinetTalkQo();
		qo.setFinetTalkid(finettalk.getFinetTalkid());
		FinetTalk Addtofinettalk=finetTalkDao.queryUnique(qo);
		if(finettalk==null){
			resultDto.setSuccess(false);
			resultDto.setResultMessage("非法操作");
			return resultDto;
		}
		if(finettalk.getNavigation()!=null) {
			Addtofinettalk.setNavigation(finettalk.getNavigation());
		}
		if(finettalk.getTopping()==1 || finettalk.getTopping()==2 ) {
			Addtofinettalk.setTopping(finettalk.getTopping());
		}
		
		//封面
		if(finettalk.getImge()!=null) {
			Addtofinettalk.setImge(finettalk.getImge());
		}
		//标题
		if(finettalk.getTitle()!=null) {
			Addtofinettalk.setTitle(finettalk.getTitle());
		}
		if(finettalk.getTopping()==1) {
			if(finettalk.getSerialNumber()!=null) {
				Addtofinettalk.setSerialNumber(finettalk.getSerialNumber());
			}
			
		}else {
			Addtofinettalk.setSerialNumber(null);
		}

		//内容
		if(finettalk.getContent()!=null) {
			Addtofinettalk.setContent(finettalk.getContent());
		}
		finetTalkDao.update(Addtofinettalk);
		resultDto.setSuccess(true);
		return resultDto;
	}

}
